<?

require_once('common/DAO.php');

function show_Rooms_table($result, $null = '&nbsp;')
			{
				if (!is_resource($result) ||
				substr(get_resource_type($result), 0, 5) !== 'mysql') {
				return false;
				}
				
				for ($i = 0, $ii = mysql_num_fields($result); $i < $ii; $i++) {
				//$out .= '<th>' . mysql_field_name($result, $i) . '</th>';
				}
				
				echo "<table align=center border=0 bordercolor=blue>\n";
				echo "<tr>\n";
				while($row = mysql_fetch_row($result)){
					
					$roomID = $row[0];	
					$floor = $row[1];
					$roomType = $row[2];
					$MaxCapacity = $row[3];
					$color = $row[5];
					
					$aux = $floor;
						
					if($aux==1)
					{		
						$temp1 = $aux;		
						if($roomID>=100 && $roomID<=199)
						{	
							if($color=='#000000'){$fontColor='#FFFFFF';}
							else{$fontColor='#000000';}
							echo "\t<td bgcolor=".$color." width=40 height=30 align=center><font color='$fontColor'>".$roomID."</font></td>\n";	
							
						}
					}
										
						if($aux!=$temp1 )
						{
							echo "</tr>\n";
							echo "<tr>\n";

						}
									
					if($aux==2)
					{		
						$temp1 = $aux;		
						if($roomID>=200 && $roomID<=299)
						{
							if($color=='#000000'){$fontColor='#FFFFFF';}
							else{$fontColor='#000000';}
							echo "\t<td bgcolor=".$color." width=40 height=30 align=center>".$roomID."</td>\n";	
						}
					}
					
										
					if($aux==3)
					{		
						$temp1 = $aux;		
						if($roomID>=300 && $roomID<=399)
						{
							if($color=='#000000'){$fontColor='#FFFFFF';}
							else{$fontColor='#000000';}
							echo "\t<td bgcolor=".$color." width=40 height=30 align=center>".$roomID."</td>\n";	
						}
					}
						if($aux!=$temp1 )
						{
							echo "</tr>\n";
						}
						

				}//while 
			echo "</tr>\n";
			echo "</table>";
			}//funcion 

$dao = new DAO; /*Crea la instancia $dao */
$dia = $_GET['dia'];
$query = "
SELECT
tbl_Room.RoomID,
SUBSTR(CONVERT(tbl_Room.RoomID, CHAR(3)), 1, 1) AS Floor,
tbl_RoomType.Description,
tbl_RoomType.MaxCapacity,
tbl_Status.Description,
tbl_Status.Color
FROM tbl_Room
INNER JOIN tbl_RoomType ON tbl_Room.RoomTypeID = tbl_RoomType.RoomTypeID
INNER JOIN tbl_RoomStatus ON tbl_RoomStatus.RoomID = tbl_Room.RoomID
INNER JOIN tbl_Status ON tbl_RoomStatus.StatusID = tbl_Status.StatusID
WHERE tbl_RoomStatus.Date = (CURDATE() + '$dia')

UNION ALL

SELECT
tbl_Room.RoomID,
SUBSTR(CONVERT(tbl_Room.RoomID, CHAR(3)), 1, 1) AS Floor,
tbl_RoomType.Description,
tbl_RoomType.MaxCapacity,
(SELECT Description FROM tbl_Status WHERE StatusID = 1),
(SELECT Color FROM tbl_Status WHERE StatusID = 1)
FROM tbl_Room
INNER JOIN tbl_RoomType ON tbl_Room.RoomTypeID = tbl_RoomType.RoomTypeID
WHERE tbl_Room.RoomID NOT IN (
SELECT tbl_RoomStatus.RoomID FROM tbl_RoomStatus WHERE tbl_RoomStatus.Date = (CURDATE() + '$dia'))
ORDER BY 1 ASC;
"; /* Creo la variable con el query*/

$result=$dao->run_query($query); /* Utilizo el metodo run_query de $dao */

//$dao->mysql_draw_table($result); /* Dibujo la tabla con el resultado */
 
//echo $dao->fnSQLtoHTML($query);


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Estatus Habitaciones</title>
</head> 
<body>
<div align="center">
<a href="estatusHabitaciones.php?dia=-1"><--</a><a href="estatusHabitaciones.php">&nbsp;&nbsp;HOY&nbsp;&nbsp;</a><a href="estatusHabitaciones.php?dia=+1"> --> </a></div>
<? show_Rooms_table($result); ?> 
</body>
</html>

